<?php
/*
 * 手机客户端店铺-购物车清单接口
 * 2014-02-27
 * 2014-05-08 (已查) 
 */
include "inc/public_header.php";

include "func/user.php";				//用户信息处理函数


$reJson = array(); //构建返回值

/*
 * 常量
 */

$img_Path = "http://www.chinalaohu.com/modules/miniature.php?w=150&h=150&p=/uploads/shop/productImg/";

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid = $uInfoArr["uid"];//用户信息主键

$reJson["success"] 	= "1";

	$shops 		= array();
	$goods 	= array();
	
	
	$sql = "SELECT DISTINCT(t2.shop_id),t2.shop_name FROM `shop_product_gwc` as t1, `shop_info` as t2 where t1.shop_id=t2.shop_id and t1.uid='".$uid."' order by t1.id desc";
	$db->query($sql);
	while($db->next_record()){	
		$sql1 = "SELECT t2.product_id,t2.product_name,t2.image,t1.price,t2.material,t2.material_other,t2.color,t2.size,t2.quantity,t2.salesvolume,t2.shangjia,t1.sum from shop_product_gwc as t1,shop_product as t2 where t1.product_id=t2.product_id and t1.shop_id='".$db->f("shop_id")."' and t1.uid='".$uid."' order by t1.id desc";
		$db1->query($sql1);
		while($db1->next_record()){
			$product_id	   	= $db1->f("product_id");
			$product_name 	= $db1->f("product_name");
			$image	   		= $db1->f("image");
			$price	  		= $db1->f("price");
			if ($db1->f("material") == "其他"){
			$material	   	= $db1->f("material_other");
			}else{
			$material		= $db1->f("material");
			}
			$color	   		= $db1->f("color");
			$size	   		= $db1->f("size");
			$quantity	   	= $db1->f("quantity");
			$salesvolume	= $db1->f("salesvolume");
			$remained		= $quantity-$salesvolume;
			$shangjia		= $db1->f("shangjia");
			$sum	   		= $db1->f("sum");
			if (!$sum){
			$sum = 1;
			}
			$description	= "颜色：".$color."\n";
			$description	= $description."尺寸：".$size;
			//$description	= $description."材质：".$material;
			if ($shangjia==0){
			$sql2 = "delete from shop_product_gwc where uid='".$uid."' and product_id='".$product_id."'";
			$db2->query($sql2);
			}else{
			if ($remained==0){
			$sql2 = "delete from shop_product_gwc where uid='".$uid."' and product_id='".$product_id."'";
			$db2->query($sql2);
			}else{
			$goods[] = array(
				"remained"=>$remained
				,"goodsId"=>$product_id
				,"goodsName"=>$product_name
				,"imgUrl"=>$img_Path.$image
				,"price"=>$price
				,"num"=>$sum
				,"description"=>$description
				
				
			);
			}
			}
		}
		if ($goods){
		$shops[] = array(
						"shopId"=>$db->f("shop_id")
						,"shopName"=>$db->f("shop_name")
						,"goods"=>$goods
					);
		}
		$goods = "";
	}
	
	
	
	
	/* 放入过滤器 */
	$reJson["shops"] = $shops;


echo json_encode($reJson);
die;
	
?>
